<extend name="./app/Tpl/Public/template.html" />
<block name="content_body">
	<div class="pad-lr-10">
	    <div style="padding:10px; overflow:hidden;">
	    	<div class="main_top" style="clear:both;"><h4>温馨提示：</h4>
    			<ul>
    				<li class="green">1.为单品打包，可以进行批量销售，打包商品和单品共享库存</li>
    			</ul>
	    	</div>
	    </div>
		<div class="table-list">
		    <table width="100%" cellspacing="0">
		        <thead>
		            <tr> 
		            	<th width="80">品牌</th>               
		                <th width="100">商品名称</th>
		                <th width="80">规格</th>
		                <th width="80">单位</th>
		                <th width="80">进货价</th>
		                <th width="80">零售价</th>
		                <th width="80">会员价</th>
		      			<th width="100">打包数量</th>
		      			<th align="left">操作</th>
		            </tr>
		        </thead>
		    	<tbody>
		    		<tr>
			        	<td align="center">{$detail.brand}</td>
			        	<td align="center">{$detail.name}</td>
			        	<td align="center">{$detail.spec}</td>
			        	<td align="center">{$detail.spec_unit}</td>
			        	<td align="center">{$detail.price_sale}</td>
			        	<td align="center">{$detail.price_vip}</td>
			        	<td align="center">{$detail.price_buy}</td>
			        	<td align="center">单品</td>
			        	<td align="center"></td>
			        </tr>
			        <notempty name="listGroup">
		    		<tr>
			        	<td colspan="9" style="background:#cfcfcf;font-weight:700">存在的打包商品</td>
			        </tr>
			        </notempty>
					<volist name="listGroup" id='val'>
						<form name="form_edit{$val.id}" id="form_edit{$val.id}" action="{:U('doEditGroup')}" method="post">
							<input type="hidden"  value="{$val.id}" name="id">
							<input type="hidden"  value="{$detail.cate_code2}" name="cate_code">
							<input type="hidden"  value="{$detail.id}" name="stock_prod_id">
					        <tr>
					        	<td align="center"><input type="text" class="input-text-mid" value="{$detail.brand}" name="brand"></td>
					        	<td align="center"><input type="text" class="input-text-mid" value="{$val.name}" name="name"></td>
					        	<td align="center"><input type="text" class="input-text-mid" value="{$val.spec}" name="spec"></td>
					        	<td align="center"><input type="text" class="input-text-sml" value="{$val.spec_unit}" name="spec_unit"></td>
					        	<td align="center"><input type="text" class="input-text-sml" value="{$val.price_sale}" name="price_sale"></td>
					        	<td align="center"><input type="text" class="input-text-sml" value="{$val.price_vip}" name="price_vip"></td>
					        	<td align="center"><input type="text" class="input-text-sml" value="{$val.price_buy}" name="price_buy"></td>
					        	<td align="center"><input type="text" class="input-text-sml" value="{$val.spec_qty}" name="spec_qty" onchange="chgPrice('{$val.id}')" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>	
					            <td align="left" class="btn">
					            	<input type="button"  name="form_list_btn_ckDel" value="修改" onclick="doSubmit('{$val.id}')"/>
					            </td>
					        </tr>
				        </form>
			        </volist>
			        <tr>
			        	<td colspan="9" style="background:#cfcfcf;font-weight:700">新增打包商品</td>
			        </tr>
			        
			       	<form name="form_edit" id="form_edit" action="{:U('doEditGroup')}" method="post">
						<input type="hidden"  value="{$detail.cate_code2}" name="cate_code">
						<input type="hidden"  value="{$detail.id}" name="stock_prod_id">
				        <tr>
				        	<td align="center"><input type="text" class="input-text-mid" value="{$detail.brand}" name="brand"></td>
				        	<td align="center"><input type="text" class="input-text-mid" value="{$detail.name}" name="name"></td>
				        	<td align="center"><input type="text" class="input-text-mid" value="{$detail.spec}" name="spec"></td>
				        	<td align="center"><input type="text" class="input-text-sml" value="" name="spec_unit"></td>
				        	<td align="center"><input type="text" class="input-text-sml" value="" name="price_sale"></td>
				        	<td align="center"><input type="text" class="input-text-sml" value="" name="price_vip"></td>
				        	<td align="center"><input type="text" class="input-text-sml" value="" name="price_buy"></td>
				        	<td align="center"><input type="text" class="input-text-sml" value="" name="spec_qty" onblur="chgPrice('')" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>	
				            <td align="left" class="btn">
				            	<input type="button"  name="form_list_btn_ckDel" value="添加" onclick="doSubmit('')"/>
				            </td>
				        </tr>
			        </form>
		    	</tbody>
		    </table>
		 </div>
	    
	</div>
<script type="text/javascript">

function doSubmit(id){
	var objForm = document.forms['form_edit'+id];
	var objEls = objForm.elements;
	if(objEls['name'].value==''){
		alert('商品名称不能为空！');
		return;
	}
	if(objEls['price_sale'].value==''){
		alert('推荐价不能为空！');
		return;
	}
	if(objEls['spec_qty'].value==''){
		alert('打包数量不能为空！');
		return;
	}

	objForm.submit();
}
function chgPrice(id){
	var objForm = document.forms['form_edit'+id];
	var objEls = objForm.elements;
	if(isNatNum(objForm.spec_qty.value)){
		objEls['price_buy'].value = {$detail.price_buy}*objForm.spec_qty.value;
		objEls['price_sale'].value = {$detail.price_sale}*objForm.spec_qty.value;
		objEls['price_vip'].value = {$detail.price_vip}*objForm.spec_qty.value;
	}else{
		alert("请输入正确的打包数量");
	}
	
}
</script>
</block>	